from appium import webdriver
import time
from appium.webdriver.common.appiumby import By
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions.mouse_button import MouseButton


# 连接配置信息
des = {
    "platformName": "Android",
    "platformVersion": "7.1.2",
    "deviceName": "emulator-5554",
    "appPackage": "com.android.gallery3d",
    "appActivity": ".app.GalleryActivity"
}

# 实例化驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", des)

# # 点击坐标[500, 800]的位置
# TouchAction(driver).press(x=500, y=800).release().perform()

actions = ActionChains(driver)
# 手指1
f1 = actions.w3c_actions.add_pointer_input('touch', 'f1')
f1.create_pointer_move(x=500, y=800)  # 手指移动到500，800的位置
f1.create_pointer_down()    # 按下去
f1.create_pointer_up(MouseButton.LEFT) # 抬起来
actions.perform()
time.sleep(2)

for i in range(3):
    f2 = actions.w3c_actions.add_pointer_input('touch', 'f2')
    f1.create_pointer_move(x=500, y=1000)
    f2.create_pointer_move(x=480, y=1100)
    f1.create_pointer_down()
    f2.create_pointer_down()
    f1.create_pointer_move(x=800, y=650)
    f2.create_pointer_move(x=80, y=1400)
    f1.create_pointer_up(MouseButton.LEFT)
    f2.create_pointer_up(MouseButton.LEFT)
    actions.perform()
    time.sleep(2)
time.sleep(5)
driver.quit()